//
//  OpenShopIntroVC.m
//  TerritoryShopkeeper
//
//  Created by 黄德玉 on 2018/6/3.
//  Copyright © 2018年 ZDQK. All rights reserved.
//

#import "OpenShopIntroVC.h"
#import <WebKit/WebKit.h>
#import "ApplyShopVC.h"
#import <Masonry/Masonry.h>

@interface OpenShopIntroVC ()

@property (nonatomic,strong) WKWebView * webView;
@property (nonatomic,strong) WKUserContentController * contentController;
@property (nonatomic,strong) UIButton * sureBtn;

@end

@implementation OpenShopIntroVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"开店介绍";
    [self.view addSubview:self.webView];
    [self.view addSubview:self.sureBtn];
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(15);
        make.bottom.equalTo(self.view).offset(-20);
        make.right.equalTo(self.view).offset(-15);
        make.height.equalTo(@35);
    }];
    [self _loadData];
}

- (void)_loadData{
    __weak typeof(self) weakSelf = self;
    [MYAFNetworking POST:@"api2/getOpenAShopIntroduce" parameters:@{} success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
    }];
}

- (void)sureClicked{
    ApplyShopVC * vc = [[ApplyShopVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (WKWebView *)webView{
    if (!_webView) {
        WKWebViewConfiguration *config = [WKWebViewConfiguration new];
        self.contentController = [[WKUserContentController alloc] init];
        config.userContentController = self.contentController;
        config.preferences = [WKPreferences new];
        config.preferences.minimumFontSize = 10;
        config.preferences.javaScriptEnabled = YES;
        config.preferences.javaScriptCanOpenWindowsAutomatically = NO;
        _webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:config];
//        _webView.UIDelegate = self;             
//        _webView.navigationDelegate = self;
        _webView.allowsBackForwardNavigationGestures = YES;
        
        _webView.scrollView.maximumZoomScale = 1.0;
        _webView.scrollView.minimumZoomScale   = 1.0;
        _webView.scrollView.showsHorizontalScrollIndicator = NO;
        _webView.scrollView.showsVerticalScrollIndicator = NO;
    }
    return _webView;
}


- (UIButton *)sureBtn{
    if (!_sureBtn) {
        _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sureBtn setBackgroundColor: [UIColor colorWithHex:0xd62e34 alpha:1]];
        [_sureBtn addTarget:self action:@selector(sureClicked) forControlEvents:UIControlEventTouchUpInside];
        NSString * title = @"";
        if (self.type == 0) {
            title = @"立即申请";
        }else{
            title = @"审核未通过";
        }
        [_sureBtn setTitle:title forState:UIControlStateNormal];
        [_sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _sureBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    }
    return _sureBtn;
}


@end
